package cn.wolfcode.trip.admin.controller;

import cn.wolfcode.trip.base.domain.StrategyCatalog;
import cn.wolfcode.trip.base.query.StrategyCatalogQuery;
import cn.wolfcode.trip.base.service.IStrategyCatalogService;
import cn.wolfcode.trip.base.service.IStrategyService;
import cn.wolfcode.trip.base.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/strategyCatalog")
public class StrategyCatalogController {
    @Autowired
    private IStrategyCatalogService strategyCatalogService;
    @Autowired
    private IStrategyService strategyService;
    //待发布状态的游记管理
    @RequestMapping("/list")
    public String list(@ModelAttribute("qo")StrategyCatalogQuery qo, Model model){
        model.addAttribute("result",strategyCatalogService.query(qo));
        model.addAttribute("strategys",strategyService.list());
        return "strategyCatalog/list";
    }
    //保存或者修改推荐游记
    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(StrategyCatalog strategyCatalog){
        JSONResult jsonResult = new JSONResult();
        try {
            strategyCatalogService.saveOrUpdate(strategyCatalog);
        }catch (Exception e){
            jsonResult.setMsg(e.getMessage());
        }
        return jsonResult;
    }
    //查询目录
    @RequestMapping("getCatalogByStrategyId")
    @ResponseBody
    public Object getCatalogByStrategyId(Long strategyId){

        List<StrategyCatalog> list = strategyCatalogService.getCatalogByStrategyId(strategyId);
        for (StrategyCatalog catalog : list) {
            System.out.println(catalog);
        }
        return list;
    }

}
